package com.example.swaggerDemo.controller;

import com.example.swaggerDemo.entity.MsgEntity;
import com.example.swaggerDemo.entity.OrderEntity;
import com.example.swaggerDemo.entity.SysUserEntity;
import com.example.swaggerDemo.service.PushService;
import com.example.swaggerDemo.service.SalaryService;
import com.example.swaggerDemo.service.UserService;
import com.example.swaggerDemo.service.orderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.List;

@Api("订单服务")
@RestController
@RequestMapping(value="/Order")
public class OrderController {

    @Autowired
    private orderService Service;

    @Autowired
    private SalaryService SalaryService;

    @Autowired
    private UserService SysUserDao;

    @Autowired
    private PushService pushService;

    @Autowired
    private Environment env;

    @ApiOperation(value="通过上级经纪人id查询该用户下的订单信息",notes="通过id查询该用户下的订单信息")
    @ResponseBody
    @RequestMapping(value="/findUpUserId",method= RequestMethod.POST)
    public  Object findUpUserId(@RequestParam("upuserid") String upuserid,
                                   @RequestParam("typedata") String typedata) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            List<OrderEntity> dto = Service.findUpUserId(upuserid,typedata);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }


    @ApiOperation(value="通过id查询该用户下的订单信息",notes="通过id查询该用户下的订单信息")
    @ResponseBody
    @RequestMapping(value="/findUserId",method= RequestMethod.POST)
    public   Object findUserId(@RequestParam("userid") String userid,@RequestParam("typedata") String typedata
    ) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            List<OrderEntity> dto = Service.findUserId(userid,typedata);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }

    @ApiOperation(value="通过协助人id查询该用户下的订单信息",notes="通过协助人id查询该用户下的订单信息")
    @ResponseBody
    @RequestMapping(value="/findAssitantid",method= RequestMethod.POST)
    public Object findAssitantid(@RequestParam("assitantid") String assitantid,
                                     @RequestParam("typedata") String typedata
    ) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            List<OrderEntity> dto = Service.findAssitantid(assitantid,typedata);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }


    @ApiOperation(value="查询协助订单",notes="查询协助订单")
    @ResponseBody
    @RequestMapping(value="/findadminordeisassitant",method= RequestMethod.POST)
    public Object findadminordeisassitant(  @RequestParam("isassitant") String assitantid,
                                            @RequestParam("pageindex") int pagindex,
                                            @RequestParam("pagesize") int pagesize,
                                            @RequestParam("username") String username
    ) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            List<OrderEntity> dto = Service.findadminordeisassitant(assitantid,pagindex,pagesize,username);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }


    @ApiOperation(value="经纪人查询名下需要处理的订单",notes="经纪人查询名下需要处理的订单")
    @ResponseBody
    @RequestMapping(value="/findUpUserIdByType",method= RequestMethod.POST)
    public  Object findUpUserIdByType(@RequestParam("upuserid") String upuserid,
                                     @RequestParam("typedata") String typedata,
                                      @RequestParam("statustype") String statustype,
                                      @RequestParam("pageindex") int pagindex,
                                      @RequestParam("pagesize") int pagesize) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            List<OrderEntity> dto = Service.findUpUserIdByType(upuserid,typedata,statustype,pagindex,pagesize);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }


    @ApiOperation(value="管理员查询订单",notes="管理员查询订单")
    @ResponseBody
    @RequestMapping(value="/findadminorde",method= RequestMethod.POST)
    public  Object findadminorde(
                                      @RequestParam("typedata") String typedata,
                                      @RequestParam("statustype") String statustype,
                                      @RequestParam("pageindex") int pagindex,
                                      @RequestParam("pagesize") int pagesize,
                                      @RequestParam("username") String username) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            List<OrderEntity> dto = Service.findadminorde(typedata,statustype,pagindex,pagesize,username);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }
    @ApiOperation(value="通过用户id查询该用户下的订单信息",notes="通过id查询该用户下的订单信息")
    @ResponseBody
    @RequestMapping(value="/findUserIdByType",method= RequestMethod.POST)
    public  Object findUserIdByType(@RequestParam("userid") String userid,
                                    @RequestParam("typedata") String typedata,
                                    @RequestParam("statustype") String statustype,
                                    @RequestParam("pageindex") int pagindex,
                                    @RequestParam("pagesize") int pagesize) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            List<OrderEntity> dto = Service.findUserIdByType(userid,typedata,statustype,pagindex,pagesize);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }





    @ApiOperation(value="通过订单id查询订单信息",notes="通过订单id查询订单信息")
    @ResponseBody
    @RequestMapping(value="/findOredId",method= RequestMethod.POST)
    public Object findOredId(@RequestParam("id") String id) throws SQLException
    {
        MsgEntity msg=new MsgEntity();
        try {
            OrderEntity dto = Service.findOredId(id);
            if ( dto!=null){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }

    @ApiOperation(value="添加免费祛斑信息有上级id",notes="添加免费祛斑信息有上级id")
    @ResponseBody
    @RequestMapping(value="/insertFreeByUpuserid",method= RequestMethod.POST)
    public  Object insertFreeByUpuserid(@RequestParam("userid") String userid,
                             @RequestParam("preimages") String preimages
    ) throws SQLException{
        MsgEntity msg=new MsgEntity();
        int dto=0;
        SysUserEntity user= SysUserDao.findByid(userid);
        SysUserEntity Upuser=null;
        if (user.getUpopenid()!=""&&user.getUpopenid()!=null)
        {
             Upuser= SysUserDao.findByid(user.getUpopenid());
             dto = Service.insertFreeByUpuserid(userid,preimages,Upuser.getId().toString(),Upuser.getUsername(),user.getUsername(),user.getMobile(),user.getAvatar());
        }
        else {
            dto=   Service.insertFreeByUpuserid(userid,preimages,"","",user.getUsername(),user.getMobile(),user.getAvatar());
        }
        if ( dto>0){
            pushService.push("o62Y_wcACt6pn3v2h_-usI8s8J4A",userid,user.getUsername());
            if (user.getUpopenid()!=""&&user.getUpopenid()!=null) {
                SysUserEntity user0= SysUserDao.findByid(user.getUpopenid());
                pushService.push(user0.getOpenid(), userid, user.getUsername());
            }
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="添加经纪人申请",notes="添加经纪人申请")
    @ResponseBody
    @RequestMapping(value="/inserAgent",method= RequestMethod.POST)
    public  Object inserAgent(@RequestParam("userid") String userid,
                              @RequestParam("Mobile") String Mobile,
                              @RequestParam("Address") String Address,
                              @RequestParam("Username") String Username,
                              @RequestParam("preimages") String preimages,
                              @RequestParam("hetongmoney") BigDecimal hetongmoney,
                              @RequestParam("sfz") String sfz
    ) throws SQLException{
        MsgEntity msg=new MsgEntity();
        int dto=0;
        SysUserDao.update(Username,Mobile,Address,userid);
        SysUserDao.updatesfz(sfz,userid);
        SysUserEntity user= SysUserDao.findByid(userid);
        SysUserEntity upuser= SysUserDao.findByid(user.getUpopenid());
        dto = Service.inserAgent(userid,preimages,Mobile,Address,Username,hetongmoney,user.getUpopenid(),upuser.getUsername(),user.getAvatar());
        if ( dto>0){
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="添加局部祛斑信息",notes="添加局部祛斑信息")
    @ResponseBody
    @RequestMapping(value="/insertLocal",method= RequestMethod.POST)
    public  Object insertLocal(@RequestParam("userid") String userid, @RequestParam("phone") String phone,
                    @RequestParam("address") String address, @RequestParam("username") String username,@RequestParam("hetongmoney") BigDecimal hetongmoney
    ) throws SQLException{
        int dto=0;
        MsgEntity msg=new MsgEntity();
        SysUserDao.update(username,phone,address,userid);
        SysUserEntity user= SysUserDao.findByid(userid);
        SysUserEntity Upuser=null;
        if (user.getUpopenid()!=""&&user.getUpopenid()!=null) {
            Upuser = SysUserDao.findByid(user.getUpopenid());
            dto = Service.insertLocal(userid,phone,Upuser.getId().toString(),address,Upuser.getUsername(),username,hetongmoney,user.getAvatar());
            if ( dto>0){
               pushService.pushagent(userid,"0");
                msg.msg="添加成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="添加失败";
                msg.code=false;
                msg.object=dto;
            }
        }
        else {
            msg.msg="用户信息有误，你还没有绑定上级经纪人";
            msg.code=false;
            msg.object=dto;
            return  msg;
        }

        return msg;
    }

    @ApiOperation(value="添加全套祛斑信息",notes="添加全套祛斑信息")
    @ResponseBody
    @RequestMapping(value="/insertFull",method= RequestMethod.POST)
    public  Object insertFull(@RequestParam("userid") String userid, @RequestParam("phone") String phone,
                  @RequestParam("address") String address, @RequestParam("username") String username,@RequestParam("hetongmoney") BigDecimal hetongmoney
    ) throws SQLException{
        int dto=0;
        MsgEntity msg=new MsgEntity();
        SysUserDao.update(username,phone,address,userid);
        SysUserEntity user= SysUserDao.findByid(userid);
        SysUserEntity Upuser=null;
        if (user.getUpopenid()!=""&&user.getUpopenid()!=null) {
            Upuser = SysUserDao.findByid(user.getUpopenid());
            dto = Service.insertFull(userid,phone,Upuser.getId().toString(),address,Upuser.getUsername(),username,hetongmoney,user.getAvatar());
            if ( dto>0){
                pushService.pushagent(userid,"1");
                msg.msg="添加成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="添加失败";
                msg.code=false;
                msg.object=dto;
            }
        }
        else {
            msg.msg="用户信息有误，你还没有绑定上级经纪人";
            msg.code=false;
            msg.object=dto;
            return  msg;
        }
        return msg;
    }
    @ApiOperation(value="再次访问添加全套祛斑信息",notes="再次访问添加全套祛斑信息")
    @ResponseBody
    @RequestMapping(value="/insertFullnew",method= RequestMethod.POST)
    public  Object insertFullnew(@RequestParam("id") String id) throws SQLException{
        int dto=0;
        MsgEntity msg=new MsgEntity();
        OrderEntity orde= Service.findOredId(id);
        if (orde!=null) {
            dto = Service.insertFull(orde.getUserid(),orde.getPhone(),orde.getUpuserid(),orde.getAddress(),orde.getUpusername(),orde.getUsername(),orde.getHetongmoney(),orde.getUserimg());
            if ( dto>0){
                Service.updateOrderOnce(id);
                pushService.pushUporader(orde.getUserid(),"1");
                msg.msg="添加成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="添加失败";
                msg.code=false;
                msg.object=dto;
            }
        }
        else {
            msg.msg="用户信息有误，你还没有绑定上级经纪人";
            msg.code=false;
            msg.object=dto;
            return  msg;
        }
        return msg;
    }


    @ApiOperation(value="修改订单状态",notes="修改订单状态")
    @ResponseBody
    @RequestMapping(value="/updateOrderType",method= RequestMethod.POST)
    public  Object updateOrderType(@RequestParam("id") String id, @RequestParam("status") String status){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updateOrderType(id,status);
        if ( dto>0){
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }


    @ApiOperation(value="修改订单协助人信息",notes="修改订单协助人信息")
    @ResponseBody
    @RequestMapping(value="/updatefreeOrderassitant",method= RequestMethod.POST)
    public  Object updatefreeOrderassitant(@RequestParam("id") String id, @RequestParam("assitant") String assitant, @RequestParam("assitantid") String assitantid){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updatefreeOrderassitant(id,assitant,assitantid);
        if ( dto>0){
            try {
                String userid =Service.findOredId(id).getUserid();
                pushService.pushagentass(userid,assitantid);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            msg.msg="修改成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="修改失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="修改订单状态",notes="修改订单状态")
    @ResponseBody
    @RequestMapping(value="/updateOrderTypeuser",method= RequestMethod.POST)
    public  Object updateOrderTypeuser(@RequestParam("id") String id, @RequestParam("status") String status,@RequestParam("userid") String userid,@RequestParam("userleve") String userleve){
        MsgEntity msg=new MsgEntity();

        int dto = Service.updateOrderType(id,status);
        if ( dto>0){
            SysUserDao.updateTypedata(userleve,userid);
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="修改订单状态",notes="修改订单状态")
    @ResponseBody
    @RequestMapping(value="/updatefreeOrderType",method= RequestMethod.POST)
    public  Object updatefreeOrderType(@RequestParam("id") String id, @RequestParam("status") String status,@RequestParam("remake") String remake){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updatefreeOrderType(id,status,remake);
        if ( dto>0){
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    //待做
    @ApiOperation(value="订单审核通过计算佣金",notes="订单审核通过计算佣金")
    @ResponseBody
    @RequestMapping(value="/ordecomplete",method= RequestMethod.POST)

//协助人:20%总金额
//    一级经纪人：订单提成 =100%-30%公司-20%协助(如果有)-杂费均摊
//
//    后继经纪人：订单提成 =100%-20%公司-10%上级-20%协助(如果有)-杂费均摊
//后续经纪人，，我的单你有10%。我占50，协助人20%。公司20%
//    加盟商：总公司后台选择用户级别 加盟商提成=100%-杂费(即材料费不均摊)
//类型:0=测斑,1=局部,2=升级,3=全套,4=售后,5=代理
    public  Object ordecomplete(@RequestParam("id") String id, @RequestParam("status") String status){
        MsgEntity msg=new MsgEntity();
        OrderEntity dto = null;
        SysUserEntity user=null;
        SysUserEntity Isassitantuser=null;
        SysUserEntity upuser=null;

        BigDecimal yonjing = new BigDecimal(env.getProperty("wx.yonjing"));
        BigDecimal money = new BigDecimal("0");
        BigDecimal zanfen = new BigDecimal("0");
        BigDecimal zanfenbijiao = new BigDecimal("0");
        BigDecimal jmssubtract = new BigDecimal("400");
        BigDecimal agentmoney=new BigDecimal(env.getProperty("agentuser.money").trim());//0.7
        BigDecimal assistusermoney=new BigDecimal(env.getProperty("assistuser.money").trim());//0.2
        BigDecimal upagentusermoney=new BigDecimal(env.getProperty("upagentuser.money").trim());//0.1
        BigDecimal houagentmoney=new BigDecimal(env.getProperty("agentuser4.money").trim());//0.5
        BigDecimal jionuser=new BigDecimal(env.getProperty("jionuser.money").trim());//1
        try {
            dto = Service.findOredId(id);
        } catch (SQLException e) {
            dto=null;
        }
        if ( dto!=null){
            try {
                zanfen=dto.getZafei();
                user= SysUserDao.findByid(dto.getUpuserid());//获取下单用户上级经纪人信息
                if (dto.getIsassitant()&&dto.getAssitantid()!=null)//如果申请了协助
                {
                    Isassitantuser= SysUserDao.findByid(dto.getAssitantid());//协助人用户信息
                }
                upuser=SysUserDao.findByid(user.getUpopenid());
                if (dto.getTypedata().equals("1"))//局部订单
                {
                    if (Isassitantuser!=null)//局部有协助人
                    {
                        SysUserDao.updateMateriel(Isassitantuser.getMaterielA()-1,Isassitantuser.getMaterielB(),Isassitantuser.getId().toString());
                    }
                    else {
                        SysUserDao.updateMateriel(user.getMaterielA()-1,user.getMaterielB(),user.getId().toString());
                    }
                    int flag0 = zanfen.compareTo(zanfenbijiao);

                    if (flag0>0){
                        money=(dto.getHetongmoney().subtract(zanfen)).multiply(yonjing);
                    }
                    else {
                        money=dto.getHetongmoney().multiply(yonjing);
                    }

                }
                if (dto.getTypedata().equals("3"))//全套订单
                {
                    if (Isassitantuser!=null)//全套订单
                    {
                        SysUserDao.updateMateriel(Isassitantuser.getMaterielA(),Isassitantuser.getMaterielB()-1,Isassitantuser.getId().toString());
                    }
                    else {
                        SysUserDao.updateMateriel(user.getMaterielA(),user.getMaterielB()-1,user.getId().toString());
                    }
                    int flag1 = zanfen.compareTo(zanfenbijiao);

                    if (flag1>0){
                        money = (dto.getHetongmoney().add(dto.getTotalprice()).subtract(zanfen)).multiply(yonjing);
                    }
                    else {
                        money = (dto.getHetongmoney().add(dto.getTotalprice())).multiply(yonjing);
                    }

                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            //subtract 减法 multiply 乘法
            //等级类型:0=粉丝,1=客户,2=一级经纪人,3=代理商,4=后续经纪人',
            //所有 角色 有协助 经纪人50% 协助人20% 协助人上级10%，无协助 经纪人70%，后续经纪人50%，加盟商100%-400，出现协助和后续经纪人为 一个人20%+10%
            //状态:0=客单,1=协助,2=押金，3=提现
            //type 50%与70%显示佣金，20%协助，10%红利 0 1 2
            if (upuser!=null&&user.getLevel()!=3) {
                BigDecimal upusergmoney3 = money.multiply(upagentusermoney);//上级经纪人佣金10%
                String upusergmoney33 = (String.format("%.1f", Double.parseDouble(upusergmoney3.toString())));
                SalaryService.insert(upuser.getId().toString(), upusergmoney33, id, "4", upuser.getUsername());//上级经纪人奖励
                SysUserDao.updateMoney(upuser.getMoney() + Double.parseDouble(upusergmoney33), upuser.getId().toString());
            }

            if (Isassitantuser!=null)//有协助人
            {
                Double yonjingmoney=Double.parseDouble(money.multiply(houagentmoney).toString());//经纪人佣金总额50%
                String type1money =(String.format("%.1f",Double.parseDouble(yonjingmoney.toString())));
                SalaryService.insert(user.getId().toString(),type1money ,id,"0" , user.getUsername());//经纪人人奖励
                SysUserDao.updateMoney(user.getMoney()+Double.parseDouble(type1money),user.getId().toString());

                Double assitantusergmoney2=Double.parseDouble(money.multiply(assistusermoney).toString());//协助人佣金总额20%
                String type2money =(String.format("%.1f",Double.parseDouble(assitantusergmoney2.toString())));
                SalaryService.insert(Isassitantuser.getId().toString(),type2money ,id,"1" , Isassitantuser.getUsername());//经纪人奖励
                SysUserDao.updateMoney(Isassitantuser.getMoney()+Double.parseDouble(type2money),Isassitantuser.getId().toString());

            }
            else {
                if (user.getLevel()==2)
                {
                    Double yonjingmoney2=Double.parseDouble(money.multiply(agentmoney).toString());//经纪人奖励本次计算金额70%
                    String type22money =(String.format("%.1f",Double.parseDouble(yonjingmoney2.toString())));
                    SalaryService.insert(user.getId().toString(),type22money ,id,"0" , user.getUsername());
                    SysUserDao.updateMoney(user.getMoney()+Double.parseDouble(type22money),user.getId().toString());
                }
               else if (user.getLevel()==3)//加盟商
                {
                    int flag = money.compareTo(jmssubtract);
                    if (flag<0||flag==0)
                    {
                        SalaryService.insert(user.getId().toString(), "0", id, "0", user.getUsername());//加盟商奖励
                    }
                    else {
                        Double yonjingmoney3 = Double.parseDouble(money.multiply(jionuser).subtract(jmssubtract).toString());//加盟商奖励本次计算金额-杂费-400

                        String yonjingmoney33 = (String.format("%.1f", yonjingmoney3));

                        SalaryService.insert(user.getId().toString(), yonjingmoney33, id, "0", user.getUsername());//加盟商奖励

                        SysUserDao.updateMoney(user.getMoney() + Double.parseDouble(yonjingmoney33), user.getId().toString());
                    }
                }
                //后续经纪人
                else if (user.getLevel()==4)
                {
                    BigDecimal yonjingmoney5=money.multiply(agentmoney);//后续经纪人50%
                    String yonjingmoney55 =(String.format("%.1f",Double.parseDouble(yonjingmoney5.toString())));
                    SalaryService.insert(user.getId().toString(),yonjingmoney55 ,id,"0" , user.getUsername());//经纪人人奖励
                    SysUserDao.updateMoney(user.getMoney()+Double.parseDouble(yonjingmoney55),user.getId().toString());

                }
            }

            int k = Service.updateOrderType(id,status);
            msg.msg="添加成功";
            msg.code=true;
            msg.object=k;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=0;
        }
        return msg;
    }


    @ApiOperation(value="修改订单状态为协助",notes="修改订单状态为协助")
    @ResponseBody
    @RequestMapping(value="/updateOrderisassitant",method= RequestMethod.POST)
    public  Object updateOrderisassitant(@RequestParam("id") String id){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updateOrderisassitant(id);
        if ( dto>0){
            try {
                OrderEntity dd=  Service.findOredId(id);
                pushService.pushaadmingentass(dd.getUserid(),"o62Y_wcACt6pn3v2h_-usI8s8J4A");
            } catch (SQLException e) {
                e.printStackTrace();
            }

            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="局部订单修改状态为待确认废弃",notes="局部订单修改状态为待确认")
    @ResponseBody
    @RequestMapping(value="/updateOrderLocal",method= RequestMethod.POST)
    public  Object updateOrderLocal(@RequestParam("userid") String userid,@RequestParam("id") String id, @RequestParam("preimages") String preimages){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updateOrderLocal(id,preimages);
        SysUserEntity user = null;

        if ( dto>0){
            try {
                user = SysUserDao.findByid(userid);
                SysUserDao.updateMateriel(user.getMaterielA()-1,user.getMaterielA()-1,userid);
            } catch (SQLException e) {
                msg.msg="修改用户物料失败，但是订单修改成功！"+ e.getMessage();
                msg.code=false;
                msg.object=dto;
                return msg;
            }
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }


    @ApiOperation(value="局部订单修改状态为已完成待审核",notes="局部订单修改状态为已完成待审核")
    @ResponseBody
    @RequestMapping(value="/updateOrderLocalOk",method= RequestMethod.POST)
    public  Object updateOrderLocalOk(@RequestParam("id") String id, @RequestParam("zafei") BigDecimal zafei,
                           @RequestParam("zafeimingxi") String zafeimingxi, @RequestParam("afterimages") String afterimages){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updateOrderLocalOk(id,zafei,zafeimingxi,afterimages);
        if ( dto>0){
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }


    @ApiOperation(value="全套订单确认订单并且 修改状态为待支付尾款",notes="全套订单确认订单并且 修改状态为待支付尾款")
    @ResponseBody
    @RequestMapping(value="/updateOrderFull",method= RequestMethod.POST)
    public  Object updateOrderFull(@RequestParam("id") String id,
                        @RequestParam("preimages") String preimages,
                        @RequestParam("totalprice") BigDecimal totalprice,
                        @RequestParam("hetongimages") String hetongimages
    ){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updateOrderFull(id,preimages,totalprice,hetongimages);
        if ( dto>0){
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="全套订单修改状态为已完成待支付尾款",notes="全套订单修改状态为已完成待支付尾款")
    @ResponseBody
    @RequestMapping(value="/updateOrderFulllOk",method= RequestMethod.POST)
    public  Object updateOrderFulllOk(@RequestParam("id") String id,
                           @RequestParam("zafei") BigDecimal zafei,
                           @RequestParam("zafeimingxi") String zafeimingxi,
                           @RequestParam("afterimages") String afterimages
    ){
        MsgEntity msg=new MsgEntity();
        int dto = Service.updateOrderFulllOk(id,zafei,zafeimingxi,afterimages);
        if ( dto>0){
            msg.msg="添加成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="添加失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }
}
